﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
using XZTZ.UMP.Public.Models.Flow;
using XZTZ.UMP.WEB.Data;

namespace XZTZ.UMP.WEB.Pages.Flow.FlowTemplateStep
{
    public class DeleteModel : PageModel
    {
        private readonly XZTZ.UMP.WEB.Data.ApplicationDbContext _context;

        public DeleteModel(XZTZ.UMP.WEB.Data.ApplicationDbContext context)
        {
            _context = context;
        }

        [BindProperty]
        public Flow_TemplateStep Flow_TemplateStep { get; set; }

        public async Task<IActionResult> OnGetAsync(Guid? id)
        {
            if (id == null)
            {
                return NotFound();
            }

            Flow_TemplateStep = await _context.Flow_TemplateStep
                .Include(f => f.Base_SignatureStepType)
                .Include(f => f.Flow_StepRule).FirstOrDefaultAsync(m => m.guidFlowStepID == id);

            if (Flow_TemplateStep == null)
            {
                return NotFound();
            }
            return Page();
        }

        public async Task<IActionResult> OnPostAsync(Guid? id)
        {
            if (id == null)
            {
                return NotFound();
            }

            Flow_TemplateStep = await _context.Flow_TemplateStep.FindAsync(id);

            if (Flow_TemplateStep != null)
            {
                _context.Flow_TemplateStep.Remove(Flow_TemplateStep);
                await _context.SaveChangesAsync();
            }

            return RedirectToPage("./Index");
        }
    }
}
